package com.springboot.controller;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.math.BigDecimal;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Map;

import com.alibaba.fastjson.JSON;

import org.springframework.web.bind.annotation.*;

import java.util.Calendar;

import java.util.Collections;

import java.util.Date;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import com.springboot.service.AnnounceServiceImp;

import com.springboot.entity.Announce;

import com.springboot.entity.AnnounceExample;

import com.springboot.entity.*;
import com.springboot.dao.*;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.multipart.MultipartFile;

@Controller

@RequestMapping(value = "/")

public class AnnounceController {


    private static final Log logger = LogFactory.getLog(AnnounceController.class);

    @Autowired
    private AnnounceServiceImp announceservice;


    //定义方法addannounce,响应页面addannounce请求

    @RequestMapping(value = "addannounce")

    public String addannounce(HttpServletRequest request, HttpServletResponse response, HttpSession session) {

        //输出日志，当前执行方法为addannounce

        logger.debug("AnnounceController.addannounce ......");

        announceservice.addannounce(request, session);

        return "addannounce";

    }


    //定义addannounceact方法,将公告信息插入到数据库的t_announce表中

    @RequestMapping(value = "addannounceact")

    public String addannounceact(HttpServletRequest request, HttpSession session, HttpServletResponse response, Announce announce, MultipartFile picfile) throws IOException {

        //输出当前方法日志，表示正在执行AnnounceController.addannounceact方法

        logger.debug("AnnounceController.addannounceact ......");

        announceservice.addannounceact(request, session, announce, picfile); //返回公告管理方法，执行公告信息的查询

        return "forward:/announcemanage.action";

    }


    @ResponseBody
    //定义addannounceactjson方法

    @RequestMapping(value = "addannounceactjson")

    public String addannounceactjson(HttpServletRequest request, HttpSession session, HttpServletResponse response, @RequestBody Announce announce) throws IOException {

        //输出当前方法日志，表示正在执行AnnounceController.addannounceactjson方法

        logger.debug("AnnounceController.addannounceactjson ......");


        //调用服务层addannounceact方法

        announceservice.addannounceactjson(announce);

        //返回addannounce方法

        return "success";

    }


    //定义announcemanage方法响应页面请求

    @RequestMapping(value = "announcemanage")

    public String announcemanage(HttpServletRequest request, HttpSession session, HttpServletResponse response) {

        //输出日志，表示当前正在执行AnnounceController.announcemanage

        logger.debug("AnnounceController.announcemanage ......");


        announceservice.announcemanage(request, session); //返回到公告管理页面

        return "announcemanage";

    }


    // 定义 announceview方法

    @RequestMapping(value = "announceview")

    public String announceview(HttpServletRequest request, HttpSession session, HttpServletResponse response) {

        // 输出日志，表示当前正在执行AnnounceController.announceview方法

        logger.debug("AnnounceController.announceview ......");


        announceservice.announceview(request, session);

        // 返回公告查看页面

        return "announceview";

    }


    // 定义 updateannounce方法

    @RequestMapping(value = "updateannounce")

    public String updateannounce(HttpServletRequest request, HttpServletResponse response, HttpSession session, int id) {

        // 输出日志AnnounceController.updateannounce，表示正在执行该方法

        logger.debug("AnnounceController.updateannounce ......");


        announceservice.updateannounce(request, session, id); // 返回修改公告页面

        return "updateannounce";

    }


    // 定义updateannounceact处理公告修改

    @RequestMapping(value = "updateannounceact")

    public String updateannounceact(HttpServletRequest request, HttpServletResponse response, Announce announce, HttpSession session, MultipartFile picfile) throws IOException {

        // 输出日志，表示正在执行当前方法AnnounceController.updateannounceact

        logger.debug("AnnounceController.updateannounceact ......");

        announceservice.updateannounceact(request, announce, session, picfile);

        // 返回公告管理方法

        return "forward:/announcemanage.action";

    }

    @ResponseBody
    // 定义updateannounceactjson处理公告修改

    @RequestMapping(value = "updateannounceactjson")

    public String updateannounceactjson(HttpServletRequest request, HttpServletResponse response, @RequestBody Announce announce, HttpSession session) throws IOException {

        // 输出日志，表示正在执行当前方法AnnounceController.updateannounceactjson

        logger.debug("AnnounceController.updateannounceactjson ......");

        announceservice.updateannounceactjson(announce);

        return "success";

    }


    // 定义deleteannounce,处理删除公告

    @RequestMapping(value = "deleteannounce")

    public String deleteannounce(HttpServletRequest request, HttpServletResponse response, HttpSession session, int id) {

        // 输出日志，表示当前正在执行AnnounceController.deleteannounce方法

        logger.debug("AnnounceController.deleteannounce ......");

        announceservice.deleteannounce(request, session, id);

        // 返回公告管理方法

        return "forward:/announcemanage.action";

    }


    @ResponseBody
    // 定义deleteannouncejson,处理删除公告

    @RequestMapping(value = "deleteannouncejson")

    public String deleteannouncejson(HttpServletRequest request, HttpServletResponse response, HttpSession session, int id) {

        // 输出日志，表示当前正在执行AnnounceController.deleteannounce方法

        logger.debug("AnnounceController.deleteannounce ......");

        announceservice.deleteannounce(request, session, id);

        return "success";

    }


    // 定义searchannounce方法，处理搜索操作

    @RequestMapping(value = "searchannounce")

    public String searchannounce(HttpServletRequest request, HttpServletResponse response, HttpSession session, String search) {

        // 输出日志，表示当前正在执行AnnounceController.searchannounce

        logger.debug("AnnounceController.searchannounce ......");


        announceservice.searchannounce(request, session, search); // 返回查询公告页面

        return "searchannounce";

    }


    @ResponseBody
    // 定义searchannouncejson方法，处理搜索操作
    @RequestMapping(value = "searchannouncejson")

    public Map searchannouncejson(HttpServletRequest request, HttpServletResponse response, HttpSession session, String search) {

        // 输出日志，表示当前正在执行AnnounceController.searchannouncejson

        logger.debug("AnnounceController.searchannouncejson ......");


        // 定义返回结果

        Map result = new HashMap();

        // 获取返回结果

        result = announceservice.searchannouncejson(search); // 将结果以json返回

        return result;

    }


    // 定义AnnouncepinglunMapper

    @RequestMapping(value = "announcedetails")

    public String announcedetails(HttpServletRequest request, HttpSession session, HttpServletResponse response, int id) {

        // 输入日志信息，表名当前执行方法为AnnounceController.announcedetails

        logger.debug("AnnounceController.announcedetails ......");


        announceservice.announcedetails(request, session, id); // 返回公告详情页面

        return "announcedetails";

    }


    @ResponseBody
    // 定义Announce详情方法

    @RequestMapping(value = "announcedetailsjson")

    public Map announcedetailsjson(HttpServletRequest request, HttpSession session, HttpServletResponse response, int id) {

        // 输入日志信息，表名当前执行方法为AnnounceController.announcedetailsjson

        logger.debug("AnnounceController.announcedetailsjson ......");


        Map result = new HashMap();

        result = announceservice.announcedetailsjson(id);

        // 将结果以json返回

        return result;

    }


}

